package org.rooster.chromosomeevaluator.rules;

import org.jgap.Gene;
import org.jgap.IChromosome;
import org.rooster.genetic.GeneIndex;
import org.rooster.genetic.GenericRule;
import org.rooster.manager.ManagerPreferencesTracker;
import org.rooster.manager.TaskManager;

/**
 * Created by IntelliJ IDEA.
 * User: manorama
 * Date: 7/22/12
 * Time: 11:06 AM
 * To change this template use File | Settings | File Templates.
 */
public class ManagerPreferencesBonusRule implements GenericRule{
    
    private int weight =1;

    public ManagerPreferencesBonusRule() {
    }

    public ManagerPreferencesBonusRule(int weight) {
        this.weight = weight;
    }

    @Override
    public double fitnessValueForRule(IChromosome chromosome) {
        double fitness = 0;

        int sectionNo;
        int sectionStartIndex;
        int sectionEndIndex;
        int managerPreferenceValue;
        Gene[] genes = chromosome.getGenes();
        
        for(int i=0; i< TaskManager.NO_OF_SECTIONS; i++) {
            sectionNo = i+1;
            sectionStartIndex = GeneIndex.getSectionStart(i);
            sectionEndIndex = GeneIndex.getSectionEnd(i);
            for (int j=sectionStartIndex; j<=sectionEndIndex; j++) {
                managerPreferenceValue = ManagerPreferencesTracker.
                        getInstance().getManagerPreference
                        (sectionNo, (Integer) genes[j].getAllele());
                fitness += managerPreferenceValue;
            }
        }
        return fitness * weight;
    }

    @Override
    public int getWeight() {
        return weight;
    }

    @Override
    public void setWeight(int value) {
        this.weight = value;
    }
}
